import React, {Component} from 'react';
import {Card, Button, Table} from 'antd';

import {getNews} from "../../api/news";

class Article extends Component {

    constructor(props) {
        super(props);
        this.state = {
            list: [],
            total: 0,
        }

    }

    componentDidMount() {
        this.getNewsList();

    }

    getNewsList = async () => {
        let info = await getNews();
        console.log(info.data);
        this.setState({
            list: info.data.data.list,
            total: info.data.data.total,
        })
    }

    columns = [
        {
            title: 'ID',
            dataIndex: 'id',
            key: 'id',
        },
        {
            title: '标题',
            dataIndex: 'title',
            key: 'title',
        },
        {
            title: '阅读数',
            dataIndex: 'viewCount',
            key: 'viewCount',
        },

        {
            title: '作者',
            dataIndex: 'author',
            key: 'author',
        },
    ]


    render() {
        return (
            <Card title="新闻列表" extra={<Button type="dashed">导出</Button>}>

                <Table dataSource={this.state.list} columns={this.columns}/>

            </Card>
        );
    }
}

export default Article;
